package a66weding.com.jiehuntong.common;

import android.app.Activity;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/5/24
 * @description :activity的管理
 */
public class MyActivityManager {

    private Map<String,Activity> mActivityMap=new HashMap<String,Activity>();
    private Map<Activity,String> repeatActivityMap=new HashMap<Activity,String>();
    /**
     * 添加一个activity
     * @param activityName
     * @param activity
     */
    public void addActivity(String activityName,Activity activity){
        mActivityMap.put(activityName,activity);
        repeatActivityMap.put(activity,activityName);
    }

    public void finishActivity(String activityName){
        Set<Map.Entry<Activity, String>> entries = repeatActivityMap.entrySet();
            for (Map.Entry<Activity, String> me:entries){
                String value = me.getValue();
                if (activityName.equals(value)){
                    Activity key = me.getKey();
                    if (key != null) {
                        key.finish();
                    }
                }
            }

    }
    public void exitApp(){
        Set<Map.Entry<String, Activity>> entries = mActivityMap.entrySet();
        for (Map.Entry<String, Activity> entyr : entries) {
            Activity mactivity = entyr.getValue();
            if(mactivity!=null) {
                mactivity.finish();

            }
        }
    }
    public Activity getActivity(String activityName){
        return    mActivityMap.get(activityName);
    }
}
